package com.expressage.service.impl;


import com.expressage.dao.SendDao;
import com.expressage.po.Send;
import com.expressage.service.SendService;
import com.expressage.vo.PostInfo;
import com.expressage.vo.SendInfo;
import com.expressage.vo.SendInfomess;
import com.expressage.vo.SendVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Gt
 * 派单业务逻辑实现类
 */
@Service("sendService")
public class SendServiceImpl implements SendService {

    @Autowired
    SendDao sendDao;

    @Override
    public List<SendVO> findAll() {
        return sendDao.findAll();
    }

    @Override
    public List<SendVO> findStaffidList(int staffid) {
        return sendDao.findStaffidList(staffid);
    }

    @Override
    public SendVO findBypid(int pid) {
        return sendDao.findBypid(pid);
    }

    @Override
    public SendVO findByodd(int odd) {
        return sendDao.findByodd(odd);
    }

    @Override
    public boolean insert(Send send) {
        send.setDate(new Timestamp(System.currentTimeMillis()));
        return sendDao.insert(send)>0?true:false;
    }

    @Override
    public boolean delete(int[] arrays) {
        return sendDao.delete(arrays)>0?true:false;
    }

    @Override
    public boolean update(Send send) {
        return sendDao.update(send)>0?true:false;
    }

    @Override
    public List<SendInfo> findStatPie() {
        return sendDao.findStat();
    }

    @Override
    public Map<String, List> findStatBar() {
        Map<String,List> map =new HashMap<>();
        List<SendInfo> list =sendDao.findStat();
        List<String> names = new ArrayList<>();
        List<Integer> values = new ArrayList<>();
        for (SendInfo info:list) {
            names.add(info.getName());
            values.add(info.getValue());
        }
        map.put("names",names);
        map.put("values",values);
        return map;
    }

    @Override
    public SendInfomess findByStaffid(int staffid) {
        return sendDao.findByStaffid(staffid);
    }
}
